
package com.jf.cloud.order.feign;

import com.jf.cloud.api.order.bo.EsOrderRefundBO;
import com.jf.cloud.api.order.feign.OrderRefundFeignClient;
import com.jf.cloud.api.order.vo.*;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.util.Json;
import com.jf.cloud.order.dto.multishop.OrderRefundDTO;
import com.jf.cloud.order.service.OrderRefundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

import java.util.Date;
import java.util.List;

/**
 * @author zz
 * @date 2020/12/25
 */
@RestController
@Hidden
public class OrderRefundFeignController implements OrderRefundFeignClient {


    @Autowired
    private OrderRefundService orderRefundService;

    @Override
    public ServerResponseEntity<Integer> getRefundStatus(Long refundId) {

        return ServerResponseEntity.success(orderRefundService.getRefundStatus(refundId));
    }

    @Override
    public ServerResponseEntity<List<OrderRefundProdEffectRespVO>> getProdRefundEffectByDateAndProdIds(List<Long> spuIds, Long startTime, Long endTime) {
        return ServerResponseEntity.success(orderRefundService.getProdRefundEffectByDateAndProdIds(spuIds,new Date(startTime),new Date(endTime)));
    }

    @Override
    public ServerResponseEntity<List<OrderRefundVO>> getOrderRefundByOrderIdAndRefundStatus(Long orderId, Integer returnMoneySts) {
        return ServerResponseEntity.success(orderRefundService.getOrderRefundByOrderIdAndRefundStatus(orderId, returnMoneySts));
    }

    @Override
    public ServerResponseEntity<List<OrderRefundSimpleVO>> listOrderIdsByRefundIds(List<Long> refundIds) {
        return ServerResponseEntity.success(orderRefundService.listOrderIdsByRefundIds(refundIds));
    }

    @Override
    public ServerResponseEntity<OrderRefundVO> getOrderRefundByRefundId(Long refundId) {
        return ServerResponseEntity.success(orderRefundService.getOrderRefundByRefundId(refundId));
    }

    @Override
    public ServerResponseEntity<EsOrderRefundBO> saveMongoAndGetEsOrderRefundInfo(Long refundId) {
        return ServerResponseEntity.success(orderRefundService.saveMongoAndGetEsOrderRefundInfo(refundId));
    }

    @Override
    public ServerResponseEntity<AccountOrderDetailVO> getAccountOrderDetail(Date startTime, Date endTime, String shopName, Long shopId) {
        AccountOrderDetailVO accountOrderDetail = orderRefundService.getAccountOrderDetail(startTime, endTime, shopName, shopId);
        return ServerResponseEntity.success(accountOrderDetail);
    }

    @Override
    public ServerResponseEntity<PageShopAccountOrderVO> listShopAccountDetail(Date startTime, Date endTime, String shopName, Integer pageSize, Integer pageNum) {
        PageShopAccountOrderVO accountDetail = orderRefundService.listShopAccountDetail(startTime, endTime, shopName, pageSize, pageNum);
        return ServerResponseEntity.success(accountDetail);
    }

    @Override
    public ServerResponseEntity<PageShopAccountOrderVO> listOrderRefundInfo(Date startTime, Date endTime, Long shopId, String shopName,Integer pageSize, Integer pageNum) {
        PageShopAccountOrderVO orderRefundInfo = orderRefundService.listOrderRefundInfo(startTime, endTime, shopId, shopName, pageSize, pageNum);
        return ServerResponseEntity.success(orderRefundInfo);
    }

    @Override
    public void doRefund(String extendInfo) {
        OrderRefundDTO orderRefundDTO = Json.parseObject(extendInfo, OrderRefundDTO.class);
        // 获取退款单信息
        com.jf.cloud.order.vo.OrderRefundVO orderRefundVO = orderRefundService.getDetailByRefundId(orderRefundDTO.getRefundId());
        orderRefundService.agreeRefund(orderRefundDTO, orderRefundVO);
    }
}
